package com.web.cms.pan.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;

import com.web.cms.pan.message.ShareRequest;
import com.web.cms.pan.message.ShareResponse;
import com.web.cms.pan.model.Share;

/**
 * 共享转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年04月09日
 */
public class ShareConvertor
{
	private ShareConvertor()
	{
	}
	
	public static Share toShare(ShareRequest request)
	{
		if (request == null)
			return null;
		
		Share share = new Share();
		share.setId(request.getId());
		share.setRefId(request.getRefId());
		share.setUserId(request.getUserId());
		share.setCode(request.getCode());
		share.setName(request.getName());
		share.setCreateTime(request.getCreateTime());
		share.setPassword(request.getPassword());
		share.setCount(request.getCount());
		share.setRefType(request.getRefType());
		share.setState(request.getState());
		return share;
	}
	
	public static List<Share> toShare(List<ShareRequest> requestList)
	{
		List<Share> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (ShareRequest request : requestList)
		{
			list.add(toShare(request));
		}
		return list;
	}
	
	public static ShareResponse toResponse(Share share)
	{
		if (share == null)
			return null;
		
		ShareResponse response = new ShareResponse();
		response.setId(share.getId());
		response.setRefId(share.getRefId());
		response.setUserId(share.getUserId());
		response.setCode(share.getCode());
		response.setName(share.getName());
		response.setCreateTime(share.getCreateTime());
		response.setPassword(share.getPassword());
		response.setCount(share.getCount());
		response.setRefType(share.getRefType());
		response.setState(share.getState());
		return response;
	}
	
	public static List<ShareResponse> toResponse(List<Share> list)
	{
		List<ShareResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Share share : list)
		{
			responseList.add(toResponse(share));
		}
		return responseList;
	}
	
	public static Map<Integer, ShareResponse> toResponse(Map<Integer, Share> map)
	{
		Map<Integer, ShareResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, Share> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<ShareResponse> toResponse(Page<Share> page)
	{
		if (page == null)
			return null;
		
		Page<ShareResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
